<?php
/**
 * Created by PhpStorm.
 * User: envision
 * Date: 2018-10-17
 * Time: 14:56
 */

namespace App\Console\Commands;


use App\Models\Good;
use App\Models\IntegralGood;
use App\Models\Order;
use App\Models\OrderDetail;
use App\Models\OrderReturn;
use App\Models\Supplier;
use App\Models\TeamTask;
use App\Models\User;
use App\Models\UserPriceLog;
use App\Models\UserSaleLog;
use Illuminate\Console\Command;

class SupplierEnd extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'supplier:end';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '供应商合作到期';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        \Log::info("定时任务:供应商合作到期==============================开始时间:" . date("Y-m-d H:i:s"));
        $time = date("Y-m-d H:i:s");
        $supplierList = Supplier::where('status', 1)->where('jztime','<=', time())->get()->toArray();
        foreach ($supplierList as $value) {
            $id = $value['id'];
            Supplier::where('id', $id)->update(['status' => 2]);
            Good::where('supplier_id', $id)->update([
                'old_status' => \DB::raw('status'),
                'status' => 2
            ]);
            IntegralGood::where('supplier_id', $id)->update([
                'old_status' => \DB::raw('status'),
                'status' => 2
            ]);
        }
        \Log::info("定时任务:供应商合作到期==============================结束时间:" . date("Y-m-d H:i:s"));
    }
}
